package com.hnou.boxuegu.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hnou.boxuegu.R;
import com.hnou.boxuegu.activity.VideoPlayActivity;
import com.hnou.boxuegu.bean.VideoBean;

import java.util.List;

public class PlayHistoryAdapter extends RecyclerView.Adapter<PlayHiistoryAdapter.MyViewHolder> {
    private Context mContext;
    private List<VideoBean> vbl;

    public PlayHiistoryAdapter(Context context){
        this.mContext =context;
    }
    public void setDate(List<VideoBean> vbl){
        this.vbl = vbl;
        notifyDataSetChanged();
    }
    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View itemView = LayoutInflater.from(mContext).inflate(R.layout.play_history_list_item,null);
        MyViewHolder holder = new MyViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder( MyViewHolder holder, int position) {
        final VideoBean bean = vbl.get(position);
        holder.tv_chapter_name.setText(bean.getChapterName());
        holder.tv_video_name.setText(bean.getVideoName());
        Glide
                .with(mContext)
                .load(bean.getVideoIcon())
                .error(R.mipmap.ic_launcher)
                .into(holder.iv_icon);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent= new Intent(mContext, VideoPlayActivity.class);
                intent.putExtra("videoPath",bean.getVideoPath());
                mContext.startActivity(intent);

            }
        });

    }

    @Override
    public int getItemCount() {
        return vbl == null ? 0 : vbl.size();
    }
    class MyViewHolder extends RecyclerView.ViewHolder{
        TextView tv_chapter_name,tv_video_name;
        ImageView iv_icon;
        public MyViewHolder(@NonNull View view) {
            super(view);
            iv_icon=view.findViewById(R.id.iv_video_icon);
            tv_chapter_name=view.findViewById(R.id.tv_chapter_name);
            tv_video_name=view.findViewById(R.id.tv_video_name);
        }
    }
}
